package kr.co.cherryt.receiver;

import kr.co.cherryt.activity.CherryTActivity;
import android.app.AlertDialog;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.telephony.SmsMessage;

public class SmsBroadcastReceiver extends BroadcastReceiver {

	@Override
	public void onReceive(Context context, Intent intent) {
		//if( !CherryTActivity.bLogin ) {
			Bundle data = intent.getExtras();
			//if( data != null ) {
				Object pdus[] = (Object[])data.get("pdus");
				String message = "";
			//	String sender = "";
				
				for (Object pdu: pdus ) {
					SmsMessage part = SmsMessage.createFromPdu( (byte[])pdu );
					message += part.getDisplayMessageBody();
					//if( sender == null ) {
					//	sender = part.getDisplayOriginatingAddress();
					//}

					if( message.contains("체리티")) {
						// 문자 수신 알림
						new AlertDialog.Builder(context)
						.setIcon(android.R.drawable.ic_menu_close_clear_cancel)
						.setTitle("체리티 인증 알림")
						.setMessage(message)
						.setPositiveButton("확인", null) 
						.show();
					}
				}
			//}
	//	}
	}
}
